package Domd4;

public class test {
    public static void main(String[] args) {
        Student student1 = new Student("李四", 15, 83);
        Student student2 = new Student("张三", 20, 59.9);
        if (student1.equals(student2)) {
            System.out.println("student1 > student2");
        } else {
            System.out.println("student1 < student2");
        }
    }
}
class Student {
    private String name;
    private int age;
    private double score;
    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
    @Override
    public boolean equals(Object object) {
        if (object == null) {
            return false;
        }
        if (this == object) {
            return true; //当前对象引用的地址是否等于要比较对象的地址
        }
        //如果不是Student类对象
        if (!(object instanceof Student)) {
            return false;
        }
        //使用age作比较 注意：因为object是Object类型，向下转型才能访问Student类的属性
        return (this.age == ((Student) object).age);
    }
}
